package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.InsurerListAdapter;
import com.jt.tenant.adapter.SpecialSaleListAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetInsurerList;
import com.jt.tenant.conn.GetSpecialSaleList;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

public class InsurerListActivity extends JTActivity implements OnClickListener {

    private TextView title;

    private ListView listView;

    private ImageView iv_insurer_list;

    private List<GetInsurerList.InsurerList> mList = new ArrayList<>();

    private InsurerListAdapter mAdapter;

    private GetInsurerList getInsurerList;

    private String ss_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_insruer_list);

        initView();

    }

    @Override
    protected void onResume() {

        super.onResume();

        getInsurerList.execute(this);

    }

    private void initView() {

        (title = (TextView)findViewById(R.id.tv_title_name)).setText("选择保险公司");

        iv_insurer_list = (ImageView)findViewById(R.id.iv_insurer_list);

        listView = (ListView)findViewById(R.id.lv_insurer);

        mAdapter = new InsurerListAdapter(this,mList);

        listView.setAdapter(mAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

                Intent intent = new Intent(context,InsInfoActivity.class);

                intent.putExtra("id",mList.get(position).ID);

                startActivity(intent);

            }
        });

        getInsurerList = new GetInsurerList(new AsyCallBack<GetInsurerList.Info>(){
            @Override
            public void onSuccess(String toast, int type, GetInsurerList.Info info) throws Exception {

                super.onSuccess(toast, type,info);

                mList.clear();

                mList.addAll(info.insLists);

                mAdapter.notifyDataSetChanged();

                JTApplication.UtilAsyncBitmap.get(info.pic, iv_insurer_list, R.mipmap.loading);

            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
                if(!toast.equals("")){

                    UtilToast.show(InsurerListActivity.this, toast);

                }
            }
        });

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {


        }

    }


}
